package cn.com.dhcc.app.pub.core.util.settlement.compute.task;

import cn.com.dhcc.app.pub.core.util.settlement.compute.store.DataGroupHandler;
import cn.com.dhcc.app.pub.core.util.settlement.compute.store.DataGroupVo;
import cn.com.dhcc.app.pub.core.util.settlement.compute.store.DataProcessHandler;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;


/**
 * 存储数据任务--临时存储，当数据成功发送到交换平台上
 * @author Administrator
 *
 */
public class DataStoreTask implements Callable<Boolean>{

	
	/**
	 * 一次请求id
	 */
	private String orderId;
	
	private Map<String,List<String>> datas;
	
	private DataGroupHandler groupHandler;
	
	private DataProcessHandler processHandler;
	
	
	public DataStoreTask(String orderId, Map<String,List<String>> datas, DataGroupHandler groupHandler, DataProcessHandler processHandler) {
		super();
		this.orderId = orderId;
		this.datas = datas;
		this.groupHandler = groupHandler;
		this.processHandler=processHandler;
	}



	@Override
	public Boolean call() throws Exception {
		try {
			//先分组
			System.out.println("orderId["+orderId+"],数据循环分组先分组");
			Set<String> tableNames=datas.keySet();
			for (String tableName : tableNames) {
				System.out.println("orderId["+orderId+"],tableName["+tableName+"],开始存储....");
				System.out.println("orderId["+orderId+"],tableName["+tableName+"],分组开始....");
				DataGroupVo vo=groupHandler.group(datas.get(tableName),false);//不需要存储映射信息
				System.out.println("orderId["+orderId+"],tableName["+tableName+"],分组结束....");
				processHandler.store(orderId,tableName, vo.getHashList());
				System.out.println("orderId["+orderId+"],tableName["+tableName+"],存储结束....");
			}
			System.out.println("orderId["+orderId+"],数据循环分组存储结束");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return true;
	}

}
